import type { ListPageModel, PageModel } from '@/api/model/CommonModel';
import type { CourtModel } from '@/api/model/CourtModel';
import { request } from '@/utils/request';

const Api = {
  CreateCourt: '/court/create',
  GetCourtList: '/court/getList',
  DeleteCourt: '/court/delete',
  GetCourtInfos: '/court/courtInfo',
  UpdateCourt: '/court/update',
};

/** 创建用户 */
export const createCourt = (data: Partial<CourtModel>) => {
  return request.post<boolean>({
    url: Api.CreateCourt,
    data,
  });
};

interface IGetUserParamsSchema extends PageModel {
  courtName?: string;
}

/** 获取场地列表 */
export const getCourtList = (params: IGetUserParamsSchema) => {
  return request.get<ListPageModel<CourtModel>>({
    url: Api.GetCourtList,
    params,
    withCredentials: true,
  });
};

/** 删除场馆 */
export const deleteCourt = (courtId: string) => {
  return request.delete<ListPageModel<CourtModel>>({
    url: Api.DeleteCourt,
    params: { courtId },
  });
};

/** 根据venueId获取场馆信息 */
export const getCourtInfosById = (courtId: string) => {
  return request.get<Partial<CourtModel>>({
    url: Api.GetCourtInfos,
    params: { courtId },
  });
};

/** 更新场馆信息 */
export const updateCourt = (court: Partial<CourtModel>) => {
  return request.put<boolean>({
    url: Api.UpdateCourt,
    params: { ...court },
  });
};
